﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Sinacor.Infra.Common.Validation
{
    [DataContract(Namespace = "http://www.sinacor.com.br/Sinacor.Infra.Common.Validation/2008/08", Name = "ValidationError")]
    public class ValidationError
    {
        public ValidationError()
        {
        }

        public ValidationError(int errorNumber)
        {
            _errorNumber = errorNumber;
        }

        public ValidationError(int errorNumber, List<object> parameters)
            : this(errorNumber)
        {
            if (parameters == null)
                parameters = new List<object>();

            _parameters = parameters;
        }

        public ValidationError(int errorNumber, string errorMessage)
            : this(errorNumber)
        {
            _errorMessage = errorMessage;
        }

        public ValidationError(int errorNumber, string errorMessage, string resourceKey)
            : this(errorNumber, errorMessage)
        {
            _resourceKey = resourceKey;
        }

        public ValidationError(int errorNumber, string errorMessage, List<object> parameters)
            : this(errorNumber, errorMessage, string.Empty, parameters)
        {
        }

        public ValidationError(int errorNumber, string errorMessage, string resourceKey, List<object> parameters)
            : this(errorNumber, errorMessage, resourceKey)
        {
            if (parameters == null)
                parameters = new List<object>();

            _parameters = parameters;
        }

       
        private int _errorNumber = 0;
        /// <summary>
        /// Código do erro
        /// </summary>
        [DataMember(IsRequired = true, Name = "ErrorNumber", Order = 1)]
        public int ErrorNumber
        {
            get { return _errorNumber; }
            set { _errorNumber = value; }
        }

        private string _resourceKey = string.Empty;
        /// <summary>
        /// Resource Key da mensagem de erro
        /// </summary>
        [DataMember(IsRequired = true, Name = "ResourceKey", Order = 2)]
        public string ResourceKey
        {
            get { return _resourceKey; }
            set { _resourceKey = value; }
        }

        private string _errorMessage = string.Empty;
        /// <summary>
        /// Mensagem de erro
        /// </summary>
        [DataMember(IsRequired = true, Name = "ErrorMessage", Order = 3)]
        public string ErrorMessage
        {
            get { return _errorMessage; }
            set { _errorMessage = value; }
        }

        private List<object> _parameters = new List<object>();
        /// <summary>
        /// Parâmetros da mensagem de erro
        /// </summary>
        [DataMember(IsRequired = true, Name = "Parameters", Order = 4)]
        public List<object> Parameters
        {
            get { return _parameters; }
            set { _parameters = value; }
        }

        /// <summary>
        /// Configura a mensagem de erro
        /// </summary>
        /// <param name="message">Mensagem de erro</param>
        public void ConfigureMessage(string message)
        {
            _errorMessage = string.Format("{0} - {1}", this.ErrorNumber, message);
        }
    }
}
